﻿#region Namespace References

using System;

#endregion

namespace DynConDevCorp.OpenArch.SmartData.Interfaces.EventArgClasses
{
    /// <summary>
    /// Base Implementation for value type invariant Value Property Changes
    /// </summary>
    public class ValueChangedEventArgs : EffectEventArgs
    {
        public ValueChangedEventArgs(ISmartBase originator): base(EffectCauses.ValueChanged, originator)
        {
            
        }
    }

    /// <summary>
    /// Argument class passed with ValueChanged event.
    /// </summary>
    /// <typeparam name="TData">The type of the AT a_ TYPE.</typeparam>
    public class ValueChangedEventArgs<TData> : ValueChangedEventArgs
    {
        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="ValueChangedEventArgs&lt;TDATA&gt;"/> class.
        /// </summary>
        /// <param name="originator">The originator.</param>
        /// <param name="oldValue">The old value.</param>
        /// <param name="newValue">The new value.</param>
        public ValueChangedEventArgs(ISmartBase originator, TData oldValue, TData newValue) : base(originator)
        {
            FieldName = String.Empty;
            OldValue = oldValue;
            NewValue = newValue;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ValueChangedEventArgs&lt;TData&gt;"/> class.
        /// </summary>
        /// <param name="args">The <see cref="DynConDevCorp.OpenArch.SmartData.Interfaces.EventArgClasses.ValueChangedEventArgs&lt;TData&gt;"/> instance containing the event data.</param>
        /// <param name="fieldName">Name of the field.</param>
        public ValueChangedEventArgs(ValueChangedEventArgs<TData> args, string fieldName)
            : base(args.Originator)
        {
            FieldName = String.IsNullOrEmpty(args.FieldName)
                            ? fieldName
                            : String.Format("{0}.{1}", fieldName, args.FieldName);
            OldValue = args.OldValue;
            NewValue = args.NewValue;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ValueChangedEventArgs&lt;TDATA&gt;"/> class.
        /// </summary>
        /// <param name="originator">The originator.</param>
        /// <param name="fieldName">Name of the field.</param>
        /// <param name="oldValue">The old value.</param>
        /// <param name="newValue">The new value.</param>
        public ValueChangedEventArgs(ISmartBase originator, string fieldName, TData oldValue, TData newValue)
            : base(originator)
        {
            FieldName = fieldName;
            OldValue = oldValue;
            NewValue = newValue;
        }

        #endregion

        #region Public Static Methods

        /// <summary>
        /// Makes the field args.
        /// </summary>
        /// <param name="originator">The originator.</param>
        /// <param name="fieldName">Name of the field.</param>
        /// <returns></returns>
        public FieldValueChangedEventArgs MakeFieldArgs(ISmartEntity originator, string fieldName)
        {
            return new FieldValueChangedEventArgs(originator, fieldName, OldValue, NewValue);
        }

        #endregion

        #region Public Instance Properties

        /// <summary>
        /// Gets or sets the name of the field.
        /// </summary>
        /// <value>The name of the field.</value>
        public string FieldName { get; private set; }

        /// <summary>
        /// Gets or sets the new value.
        /// </summary>
        /// <value>The new value.</value>
        public TData NewValue { get; private set; }

        /// <summary>
        /// Gets or sets the old value.
        /// </summary>
        /// <value>The old value.</value>
        public TData OldValue { get; private set; }

        #endregion
    }

}